package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.PaymentDAO;

@WebServlet("/paycheck")
public class PaymentServlet extends HttpServlet{
	private PaymentDAO paydao=new PaymentDAO();

	 public PaymentServlet() {
	        super();
	    }

	 public void doGet(HttpServletRequest request, HttpServletResponse response)
	            throws ServletException, IOException {
	        doPost(request,response);
	    }
	 public void doPost(HttpServletRequest request, HttpServletResponse response)
	            throws ServletException, IOException {
		  request.setCharacterEncoding("utf-8");
		  String method = request.getParameter("method");
		  modifypayment(request);
	      request.getRequestDispatcher("/payment.jsp").forward(request, response);   	
	  }

	private void modifypayment(HttpServletRequest request) {
		try {
			String cno=request.getParameter("cno");
			String payprice=request.getParameter("payprice");
			String contractp=request.getParameter("contractp");
			this.paydao.payment_submit(cno,payprice,contractp);
	        
		 } catch (Exception ex) {
			 
	         request.setAttribute("errormsg", ex.getMessage());
	         
	     }
	}

}
